using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Xml;

namespace ExperimentManager {
  class Experiment {
    public static string ServerPath;
    public static string ClientPath;
    public static string ConnectionParams;
    public static string DepthOfSearch;

    // Vytvari novou instatnci problemu a spousti jeji reseni
    public static void StartExperimentRun(string logFilename, int[] currentWeights) {
      // spusteni serveru
      Process server = new Process();
      server.StartInfo.FileName = Experiment.ServerPath;
      server.StartInfo.Arguments = Experiment.ConnectionParams + " " + logFilename;
      server.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

      //spusteni 1. klienta
      Process client1 = new Process();
      client1.StartInfo.FileName = Experiment.ClientPath;
      client1.StartInfo.Arguments = Experiment.ConnectionParams + " Client_1.0 " + Experiment.DepthOfSearch + " 0" + String.Format(" {0:D} {1:D} {2:D} {3:D} {4:D} {5:D}", currentWeights[0], currentWeights[1], currentWeights[2], currentWeights[3], currentWeights[4], currentWeights[5]);
      client1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

      // spusteni 2. klienta
      Process client2 = new Process();
      client2.StartInfo.FileName = Experiment.ClientPath;
      //client2.StartInfo.Arguments = Experiment.ConnectionParams + " Client_1.0 " + Experiment.DepthOfSearch + String.Format(" {0:D} {1:D} {2:D} {3:D} {4:D} {5:D}", -1 * currentWeights[1], -1 * currentWeights[0], -currentWeights[3], -1 * currentWeights[2], -1 * currentWeights[5], -1 * currentWeights[4]);
      client2.StartInfo.Arguments = Experiment.ConnectionParams + " Client_1.0 " + Experiment.DepthOfSearch + " 1" + String.Format(" {0:D} {1:D} {2:D} {3:D} {4:D} {5:D}", currentWeights[0], currentWeights[1], currentWeights[2], currentWeights[3], currentWeights[4], currentWeights[5]);
      client2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;      

      server.Start();
      System.Threading.Thread.Sleep(1000);
      client1.Start();
      System.Threading.Thread.Sleep(1000);
      client2.Start();

      // reseni ulohy je skonceno, pokud aplikace server dokonci svoji cinnost
      server.WaitForExit();
    }
    
  }
}
